<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('社团组织信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>机构名称：</label>
                            <input name="deptId" type="hidden" id="treeId"/>
                            <input name="deptName" onclick="selectDeptTree()" id="treeName" type="text"
                                   placeholder="请选择归属机构" autocomplete="off">
                        </li>
                        <li>
                            <label>营销人员：</label>
                            <input type="text" name="userName"/>
                        </li>
                        <li>
                            <label>客群名称：</label>
                            <select name="customerId" th:with="type=${@customerGroupInfo.selectEcardCustomerGroupInfo()}">
                                <option value="">所有</option>
                                <option th:each="group : ${type}" th:text="${group.customerGroupName}"
                                        th:value="${group.id}"></option>
                            </select>
                        </li>
                        <li>
                            <label>组织名称：</label>
                            <input type="text" name="organizeName"/>
                        </li>
                        <li>
                            <label>组织类型：</label>
                            <select name="organizeType" th:with="type=${@dict.getType('ecard_organize_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>是否释放：</label>
                            <select name="releaseSts" >
                                <option value="">所有</option>
                                <option value="是">是</option>
                                <option value="否">否</option>
                            </select>
                        </li>
                        <li>
                            <p>状态：</p>
                            <select name="state" th:with="type=${@dict.getType('sys_sts')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-date">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" readonly
                                   name="params[startDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" readonly
                                   name="params[endDate]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-primary multiple disabled" onclick="handOver()"
               shiro:hasPermission="ecard:customerGroup:organize:handOver">
                <i class="fa fa-exchange"></i> 转交
            </a>
            <a class="btn btn-success multiple disabled" onclick="release()"
               shiro:hasPermission="ecard:customerGroup:organize:handOver">
                <i class="fa fa-hourglass-end"></i> 释放
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()"
               shiro:hasPermission="ecard:customerGroup:organize:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary multiple disabled" onclick="enable()"
               shiro:hasPermission="ecard:customerGroup:organize:switchOver">
                <i class="fa fa-plus"></i> 启用
            </a>
            <a class="btn btn-danger multiple disabled" onclick="disable()"
               shiro:hasPermission="ecard:customerGroup:organize:switchOver">
                <i class="fa fa fa-remove"></i> 停用
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var organizeTypeDatas = [[${@dict.getType('ecard_organize_type')}]];
    var commonYesNoDatas = [[${@dict.getType('common_yes_no')}]];
    var visitFlag = [[${@permission.hasPermi('merchant:info:visit')}]];
    var prefix = ctx + "ecard/customerGroup/organize";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "社团组织信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '主键id',
                    visible: false
                },
                {
                    field: 'customerGroupName',
                    title: '客群名称'
                },
                {
                    field: 'organizeName',
                    title: '组织名称'
                },
                {
                    field: 'organizeType',
                    title: '组织类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(organizeTypeDatas, value);
                    }
                }/*,
                {
                    field: 'isConnected',
                    title: '是否对接',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(commonYesNoDatas, value);
                    }
                }*/,
                {
                    field: 'organizeContacts',
                    title: '组织联系人'
                },
                {
                    field: 'organizePhone',
                    title: '组织联系电话'
                },
                {
                    field: 'organizeAddress',
                    title: '组织地址'
                },
                {
                    field: 'organizePic',
                    title: '组织图片',
                    formatter: function (value, row, index) {
                        return $.table.imageView(row.organizePic, 300, 500);
                    }
                },
                {
                    field: 'userName',
                    title: '客户经理'
                },
                {
                    field: 'deptName',
                    title: '归属机构'
                },
                {
                    field: 'creationTime',
                    title: '创建时间'
                },
                {
                    field: 'state',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + visitFlag + '" href="javascript:void(0)" onclick="organizeVisit(\'' + row.id + '\')"><i class="fa fa-list-ul"></i>拜访记录</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    /* 选择机构树 */
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择部门',
            width: "380",
            url: url,
            callBack: doSub
        };
        $.modal.openOptions(options);
    }

    function doSub(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function reset() {
        $('#treeId').val('')
        $.form.reset();
    }

    //拜访记录
    function organizeVisit(id) {
        var url = 'ecard/customerGroup/organize/visit/' + id;
        $.modal.openTab("社团组织拜访记录", url);
    }

    //转交社团组织信息
    function handOver() {
        var rows = $.table.selectFirstColumns();
        var url = prefix + '/handOver/' + rows.join();
        var options = {
            title: '选择客户经理',
            width: 900,
            height: 700,
            url: url,
            callBack: doSubmit
        };
        $.modal.confirm("确认要移交选中的【" + rows.length + "】个社团组织吗?", function () {
            $.modal.openOptions(options);
        });

    }

    function doSubmit(index, layero) {
        var result = layero.find("iframe")[0].contentWindow.submitHandler();
        if (result) {
            setTimeout("$.table.refresh()",600);
            $.modal.close(index);
            $.modal.msgSuccess("社团组织转交成功！");

        }
    }

    //释放客户
    function release() {
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("确认要释放选中的【" + rows.length + "】个社团组织吗?", function () {
            var data = {"ids": rows.join()};
            $.operate.submit(prefix + "/release", "post", "json", data);
        });
    }

    /* 状态显示 */
    function statusTools(row) {
        if (row.state == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\"></i> ';
        }
    }
    /* 停用 */
    function disable() {
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("确认要停用选中的【" + rows.length + "】个社团组织吗?", function () {
            var data = {"ids": rows.join(), "state": 0};
            $.operate.submit(prefix + "/switchOver", "post", "json", data);
        });
    }

    /* 启用 */
    function enable() {
        var rows = $.table.selectFirstColumns();
        $.modal.confirm("确认要启用选中的【" + rows.length + "】个社团组织吗?", function () {
            var data = {"ids": rows.join(), "state": 1};
            $.operate.submit(prefix + "/switchOver", "post", "json", data);
        });
    }
</script>
</body>
</html>